﻿@model XW.Data.SysUser
@{
    Layout = "_LayoutEdit";
}
 
@section css {
    <style>
    body {
        background-color: #ffffff;
    }
    </style>
}
<div class="layui-form layuimini-form layui-layout-admin">
        <input type="hidden" name="id" value="@Model.Id" />
        <div class="layui-form-item">
            <label class="layui-form-label required" for="UserName">用户名</label>
            <div class="layui-input-block">
            @if (@Model.Id > 0)
            {
                <input id="UserName" type="text" name="Account" readonly disabled lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="@Model.Account" class="layui-input">
            }
            else {
                <input id="UserName"  type="text" name="Account" lay-reqtext="用户名不能为空" lay-verify="required" placeholder="请输入用户名" value="@Model.Account" class="layui-input">
            
            }
            <tip>填写自己账号的名称。</tip>
            </div>
        </div>
         @if (@Model.Id == 0)
            {
        <div class="layui-form-item">
            <label class="layui-form-label required">密码</label>
            <div class="layui-input-block">
            <input type="text" name="Password"   lay-reqtext="密码不能为空" lay-verify="required"  placeholder="请输入密码" value="@Model.Password" class="layui-input">
            <tip>填写密码。</tip>
            </div>
        </div>
            }

        <div class="layui-form-item">
        <label for="RealName" class="layui-form-label required">姓名</label>
            <div class="layui-input-block">

            <input type="text" name="RealName" id="RealName" value="@Model.RealName" class="layui-input" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" />
            </div>
        </div>
        <div class="layui-form-item">
            <label for="NickName" class="layui-form-label required">昵称</label>
            <div class="layui-input-block"> 
                <input type="text" name="NickName" id="NickName" value="@Model.NickName" class="layui-input" lay-verify="required" lay-reqtext="昵称不能为空" placeholder="请输入昵称" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required" for="phone">手机</label>
            <div class="layui-input-block">
                <input type="number" id="phone" name="phone" lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机" value="@Model.Phone" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" for="Email">邮箱</label>
            <div class="layui-input-block">
                <input type="email" id="Email" name="email" placeholder="请输入邮箱" value="@Model.Email" class="layui-input">
            </div>
        </div> 
        <div class="layui-form-item layui-form-text">
            <label for="Remark" class="layui-form-label">备注信息</label>
            <div class="layui-input-block">
            <textarea name="remark" id="Remark" class="layui-textarea" placeholder="请输入备注信息">@Model.Remark</textarea>
            </div>
        </div>
    @{
        var roles = ViewData["Roles"] as List<XW.Data.SysRole>; 
        var roleList =  roles.Select(d => new SelectListItem { Value = d.Id.ToString(), Text = d.Name, Selected = Model.Roles.Contains(d.Id) });

        }
    <div class="layui-form-item">
        <label class="layui-form-label required" for="Roles">角色</label>
        <div class="layui-input-block">
            <select asp-for="Roles" asp-items="roleList" class="xxui-combobox" lay-ignore multiple="multiple" style="width:200px;">
            </select> 
            <tip>填写角色的排序。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <div class="layui-footer">
                <button class="layui-btn layui-btn-primary" lay-on="form-colose">关闭</button>
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div> 
@section js{

    <script>
        var baseUrl = '@(Url.Content("~/"))';
        layui.use(['form','multiSelect'], function () {
            var form = layui.form,
                layer = layui.layer,
                util = layui.util,
                $ = layui.$;
           util.on('lay-on', {
                'form-colose': function(othis){
                  var l = parent.layer;
                  var iframeIndex = l.getFrameIndex(window.name);
                  l.close(iframeIndex);
                },
            });
            //监听提交
            form.on('submit(saveBtn)', function (data) {
                var loadIndex = layer.load(3);
                console.log('submit(saveBtn)',data);
                var datas = data.field;
                var roles = $("#Roles").combobox("getValues");
                //$("[name='Roles']").val();

                
                if(!roles){
                    roles = [];
                }
                datas.Roles = roles.join(',');
                $.ajax({
                    url: '@(Url.Content("~/sys/user/save"))',
                    data: datas,
                    method: 'post',
                    success: function (d) {
                        layer.close(loadIndex);
                        if (d.resultCode == "200") {
                            var l = parent.layer;
                            l.msg('保存成功');
                            var iframeIndex = l.getFrameIndex(window.name);
                            l.close(iframeIndex);   
                        } else {
                            layer.msg(d.message);
                        }
                    },
                    error: function (e) {
                        layer.close(loadIndex);
                    }
                });

                return false;
            });

        });
    </script>
} 